<template>
    <div id="ds34">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>系统管理</BreadcrumbItem>
            <BreadcrumbItem>系统登录日志</BreadcrumbItem>
        </Breadcrumb>
        <div style="margin-top: 10px">
            <Table :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
                   v-if="data&&data.length>0"></Table>
            <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
                  style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator v-if="data&&data.length>0"/>
            <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
                总计 {{pageTotal}} 条数据
            </div>
        </div>
        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>

    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                loading: false,
                pageTotal: 0,
                curPage: 0,
                columns: [
                    {
                        title: '用户类型',
                        key: 'roleId1'
                    },
                    {
                        title: '手机号',
                        key: 'mobile'
                    },
                    {
                        title: '状态',
                        key: 'status1'
                    },
                    {
                        title: '登录时间',
                        key: 'create1'
                    }
                ],
                data: []
            }
        },
        mounted(){
            this.getData();
        },
        methods: {
            pageChange(page){
                this.getData(page);
            },
            getData(page){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (page) {
                    param.append('pageId', page + "");
                }

                this.loading = true;
                Axios.post(ipServer + "system/selectSystemLoginLogs", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {
                                    res.data.data.result[i].create1 = sessionUtils.timestampToTime(res.data.data.result[i].create);

                                    if (res.data.data.result[i].status == "1") {
                                        res.data.data.result[i].status1 = "正常";
                                    } else {
                                        res.data.data.result[i].status1 = "禁用";
                                    }
                                    if (res.data.data.result[i].roleId == "1") {
                                        res.data.data.result[i].roleId1 = "管理员";
                                    } else {
                                        res.data.data.result[i].roleId1 = "普通用户";
                                    }

                                }
                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>